package com.example.xinai.Controller;

import com.example.xinai.Entity.AjaxResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY;

@RequiredArgsConstructor
@RestController
@RequestMapping("/chat")
@Slf4j
public class AgentChatController {
    private final ChatClient chatClient;
    @RequestMapping("/send")
    public AjaxResult prompt(@RequestParam("question") String question, @RequestParam("chatId") String chatId) {

       String content = chatClient.prompt()
                .user(question)
               .advisors(a->a.param(CHAT_MEMORY_CONVERSATION_ID_KEY,chatId))
                .call()

                .content();
        Map<String, Object> reply = new HashMap<>();
        reply.put("content", content);
        Map<String, Object> data = new HashMap<>();
        data.put("reply", reply);
        return AjaxResult.success(data);
    }
}
